package io.github.yotta.logger.message.support;

import io.github.yotta.logger.api.request.LogCreateRequest;
import io.github.yotta.logger.message.model.LogOperationDataMessage;

/**
 * @author yotta
 * @date 2023/4/14 13:45
 */
public abstract class AbstractManagerLogSaveProvider implements LogSaveProvider {

    @Override
    public void save(LogOperationDataMessage logMsg) {
        final LogCreateRequest logCreateRequest = from(logMsg);
        save(logCreateRequest);
    }

    protected abstract void save(LogCreateRequest logCreateRequest);

    protected LogCreateRequest from(LogOperationDataMessage message) {
        final LogCreateRequest logCreateRequest = new LogCreateRequest();
        logCreateRequest.setApplication(message.getApplication());
        logCreateRequest.setName(message.getName());
        logCreateRequest.setModel(message.getModel());
        logCreateRequest.setRequestJson(message.getRequestJson());
        logCreateRequest.setResponseJson(message.getResponseJson());
        logCreateRequest.setOccurTime(message.getOccurTime());
        logCreateRequest.setOperatorId(message.getOperatorId());
        logCreateRequest.setOperatorName(message.getOperatorName());
        logCreateRequest.setIsSuccess(message.getIsSuccess());
        logCreateRequest.setMessage(message.getMessage());
        logCreateRequest.setExtra(message.getExtra());
        logCreateRequest.setTenantId(message.getTenantId());
        logCreateRequest.setBizId(message.getBizId());
        return logCreateRequest;
    }

}
